/**
 * 
 */
package com.vision.sales.cm.db.data;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import net.sf.gilead.pojo.gwt.LightEntity;

/**
 * @author Mark
 *
 */
@Entity
@Table(name = Product.TABLE)
public class Product extends LightEntity implements Serializable {
	
	public static interface FieldSpecs {
		int CODE_MAX = 15;
		int NAME_MAX = 60;
		int GROUP_CODE_MAX = 15;
		int DESC_MAX = 300;
	}

	private static final long serialVersionUID = -4912296665309759926L;
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	public static final String TABLE = "product";
	public static final String COL_ID = "id";
	public static final String COL_CODE = "code";
	public static final String COL_NAME = "name";
	public static final String COL_GROUP_CODE = "group_code";
	public static final String COL_DESCRIPTION = "description";

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "sproduct")
	@SequenceGenerator(name = "sproduct", sequenceName = "product_seq")
	@Column(name = COL_ID)
	private Long id;
	
	@Column(name = COL_CODE, nullable = false, unique = true, updatable = false, length = FieldSpecs.CODE_MAX)	
	private String code;
	
	@Column(name = COL_NAME, nullable = false, updatable = false, length = FieldSpecs.NAME_MAX)
	private String name;
	
	@Column(name = COL_GROUP_CODE, nullable = false, length = FieldSpecs.GROUP_CODE_MAX)
	private String group;
	
	@Column(name = COL_DESCRIPTION, nullable = true, length = FieldSpecs.DESC_MAX)
	private String description;

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	public Product() {
		
	}
	
	@Override
	public boolean equals(Object object) {
		if (object instanceof Product) {
			Product o = (Product) object;
			return id.equals(o.id);
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return id == null ? super.hashCode() : id.hashCode();
	}
	
	@Override
	public String toString() {
		return id + ": " + name + " (" + code + ")";
	}
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
